// pages/dailiangfang/demand.js
Page({
  data: {
    index: -1,
    indexOmen: -1,
    scrollviewheight: '',
    ci_rwdid: '',
    showView: true,
    showColor: false,
    showColor2: false,
    ca_IntentionalStyle: '',       // 意向风格
    ca_SoftFurniture: '',          // 家具软装
    ca_IntelligentWeakCurrent: '', // 智能弱电
    ca_FengShuiRequirements: ''    // 风水要求
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数

    var that = this
    that.setData({
      ci_rwdid: options.ci_rwdid,
    })
    // 获取系统高度
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollviewheight: res.screenHeight - 134
        })
      },
    })
    // 拿到缓存数据
    wx.getStorage({
      key: 'ca_IntentionalStyle',
      success: function (res) {
        console.log(res.data)
        if (res.data != '') {
          that.setData({
            // showView: (!that.data.showView),
            ca_IntentionalStyle: res.data
          })
        }
      },
    })
    wx.getStorage({
      key: 'ca_FengShuiRequirements',
      success: function (res) {
        console.log(res.data)
        if (res.data != '') {
          that.setData({
            showView4: (!that.data.showView4),
            ca_FengShuiRequirements: res.data
          })
        }
      },
    })
    //接口一获取数据
    wx.request({
      url: 'https://api.wenes.cn/JD/GetProDemandInfo?ci_rwdid=' + that.data.ci_rwdid,
      success: function (res) {
        console.log(res.data.Table[0])
        var item = res.data.Table[0]
        that.setData({
          ca_IntentionalStyle: item.ca_IntentionalStyle,
          ca_SoftFurniture: item.ca_SoftFurniture,
          ca_IntelligentWeakCurrent: item.ca_IntelligentWeakCurrent,
          ca_FengShuiRequirements: item.ca_FengShuiRequirements,
        })
      }
    })
  },
  
  //点击标题隐藏和显示
  title_intentional: function (e) {
    var that = this
    console.log(e)
    that.setData({
    })
  },
  // 点击选项卡--意向风格
  intentional1: function (e) {
    var that = this
    console.log(e)
    that.setData({
      ca_IntentionalStyle: '现代简约',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional2: function (e) {
    var that = this
    console.log(e)
    that.setData({
      ca_IntentionalStyle: '简欧风格',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional3: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '新中式',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional4: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '个性前卫',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional5: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '东南亚风格',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional6: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '古典欧式',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional7: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '古典中式',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional8: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '地中海风格',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional9: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '田园风格',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional10: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '韩式风格',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional11: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '日式风格',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional12: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '后现代',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional13: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '美式乡村',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional14: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '都市风格',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional15: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: '时尚混搭',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },
  intentional16: function (e) {
    var that = this
    that.setData({
      ca_IntentionalStyle: 'LOFT',
      index: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_IntentionalStyle',
      data: that.data.ca_IntentionalStyle,
    })
  },

  //点击标题隐藏和显示
  title_spaceset: function () {
    var that = this
    that.setData({
    })
  },
  // 点击选项卡--控件配套（多选）
  softfurniture: function (e) {
    var that = this
    that.setData({
      showColor: (!that.data.showColor),
    })
    if (that.data.showColor == true) {
      that.setData({
        ca_SoftFurniture: 1
      })
      console.log('ca_SoftFurniture ', that.data.ca_SoftFurniture)
    } else {
      that.setData({
        ca_SoftFurniture: 2
      })
      console.log('ca_SoftFurniture ', that.data.ca_SoftFurniture)
    }
    wx.setStorage({
      key: 'ca_SoftFurniture',
      data: that.data.ca_SoftFurniture,
    })
  },
  intelligent: function (e) {
    var that = this
    that.setData({
      showColor2: (!that.data.showColor2)
    })
    if (that.data.showColor2 == true) {
      that.setData({
        ca_IntelligentWeakCurrent: 1
      })
      console.log('ca_IntelligentWeakCurrent ', that.data.ca_IntelligentWeakCurrent)
    } else {
      that.setData({
        ca_IntelligentWeakCurrent: 2
      })
      console.log('ca_IntelligentWeakCurrent ', that.data.ca_IntelligentWeakCurrent)
    }
    wx.setStorage({
      key: 'ca_IntelligentWeakCurrent',
      data: that.data.ca_IntelligentWeakCurrent,
    })
  },
  //点击标题隐藏和显示
  title_fengshui: function () {
    var that = this
    that.setData({
    })
  },
  // 点击选项卡--风水要求
  fengshui1: function (e) {
    var that = this
    that.setData({
      ca_FengShuiRequirements: 1,
      indexOmen: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_FengShuiRequirements',
      data: that.data.ca_FengShuiRequirements,
    })
  },
  fengshui2: function (e) {
    var that = this
    that.setData({
      ca_FengShuiRequirements: 2,
      indexOmen: e.currentTarget.dataset.id
    })
    wx.setStorage({
      key: 'ca_FengShuiRequirements',
      data: that.data.ca_FengShuiRequirements,
    })
  },

  // 提交数据
  submit: function () {
    var that = this
    if (that.data.ci_rwdid == null ||
      that.data.ca_IntentionalStyle == null ||
      that.data.ca_SoftFurniture == null ||
      that.data.ca_IntelligentWeakCurrent == null ||
      that.data.ca_FengShuiRequirements == null
    ) {
      // wx.showToast({
      //   title: '请将信息填写完整!',
      //   icon: 'warn',
      //   duration: 2000
      // })
      wx.showModal({
        title: '提示',
        content: '请将信息填写完整!',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }else{
      wx.request({
        url: 'https://api.wenes.cn/JD/UpdateProDemandInfo',
        method: 'POST',
        header: {
          'content-type': 'application/json'
        },
        data: {
          ci_rwdid: that.data.ci_rwdid,
          ca_IntentionalStyle: that.data.ca_IntentionalStyle,              // 意向风格
          ca_SoftFurniture: that.data.ca_SoftFurniture,                    // 家具软装
          ca_IntelligentWeakCurrent: that.data.ca_IntelligentWeakCurrent,  // 智能弱电
          ca_FengShuiRequirements: that.data.ca_FengShuiRequirements,      // 风水要求 
        },
        success: function (res) {
          console.log(res)
          if (res.data == 1) {
            wx.showToast({
              title: '成功',
              icon: 'success',
              duration: 2000
            })
            wx.clearStorage()
          } else {
            wx.showToast({
              title: '失败',
              icon: 'failure',
              duration: 2000
            })
          }
        }
      })
    }
   
  },

  // 页面跳转
  surroundings: function (e) {
    var that = this
    console.log(e)
    wx.redirectTo({
      url: 'surroundings?ci_rwdid=' + that.data.ci_rwdid + '&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
    })
  },
  measureroom: function (e) {
    var that = this
    wx.redirectTo({
      url: 'measureroom?ci_rwdid=' + that.data.ci_rwdid
    })
  },
  upkeep: function (e) {
    var that = this
    wx.redirectTo({
      url: 'upkeep?ci_rwdid=' + that.data.ci_rwdid
    })
  },


})